package com.flyduck.common.util;

import com.alibaba.fastjson.JSON;
import com.flyduck.common.config.FlyduckConfig;
import com.flyduck.common.vo.LoginInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: flyduck-platform
 * @description: 获取登录信息
 * @author: flyduck
 * @create: 2021-02-06 22:02
 **/
@Component
public class TokenUtil {

    @Autowired
    private FlyduckConfig flyDuckConfig;
    @Autowired
    private RedisUtil redisUtil;

    public LoginInfoVO getLoginInfo(){
        HttpServletRequest request = ServletUtil.getRequest();
        String token = request.getHeader(flyDuckConfig.getToken().getHeader());
        return JSON.parseObject(redisUtil.getCacheObject(token),LoginInfoVO.class);
    }
}
